package com.usc.aop;
import org.springframework.stereotype.Component;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

import java.util.Date;
import java.util.Random;

@Component
@Aspect

public class Myaspect {
    @Pointcut("execution(void com.usc.service.OrderService.add(..))")
    public void a(){}
    @Pointcut("execution(void com.usc.service.OrderService.delete(..))")
    public void b(){}
    @Pointcut("execution(void com.usc.service.OrderService.findInfo(..))")
    public void c(){}
    @AfterReturning(value=("name"))
    public void recordReturnValue(){
        System.out.println("成功"+ "name");
    }
    @Before("a()||b()||c()")
    public void log(){
        System.out.println("---------");
        System.out.println("hello,我是一个前置增强");
        System.out.println(new Date());
        System.out.println("---------");
    }
    @Before("a()||b()")
    public void check(){
        System.out.println("---------");
        System.out.println("权限校验增强");
        Random r = new Random();
        if(r.nextInt(2)==0){
            System.out.println("校验失败");
          throw new RuntimeException("用户没权限");
        }
        else {
            System.out.println("校验通过");
        }
        System.out.println("---------");

    }

}
